package chapter8.practice;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class ConsoleSet {
    public static void main(String[] args) {
        System.out.println("请输入20个字符串，每行一个，以回车作为每行结束:");
        Set set = new HashSet();
        Scanner scanner = new Scanner(System.in);
        int i = 0;
        while (i < 20) {
            String next = scanner.next();
            boolean flag = set.add(next);
            if(flag) {
                i++;
            } else {
                System.out.println("输入的字符串已存在,请重新输入第" + (i + 1) + "个字符串");
                continue;
            }
        }
        System.out.println("您输入的20个字符串为:" +set);
    }
}
